package com.wntms.ft.controller;

import com.alibaba.druid.sql.dialect.ads.visitor.AdsOutputVisitor;
import com.github.pagehelper.PageInfo;
import com.wntms.ft.pojo.FareForm;
import com.wntms.ft.result.Result;
import com.wntms.ft.service.FareService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/fare")
public class FareController {
    @Autowired
    private FareService fareService;

    /**
     * 查询所有
     * @return
     */
    @GetMapping("/{pageNum}/{pageSize}")
    public Result customerOrder(@PathVariable int pageNum,@PathVariable int pageSize) {
        List<FareForm> forms = fareService.findAll(pageNum,pageSize);
        if (forms != null) {
            PageInfo<FareForm> pageInfo = new PageInfo<>(forms);
            return Result.success(pageInfo, "查询成功");
        }
        return Result.error("查询失败");
    }

    /**
     * 通过时间查询所有
     * @param date
     * @return
     */
    @GetMapping("/{pageNum}/{pageSize}/{date}")
    public Result customerOrderByDate(@PathVariable int pageNum,@PathVariable int pageSize,@PathVariable String date){
        List<FareForm> forms = fareService.findByDate(pageNum,pageSize,date);
        if (forms != null) {
            PageInfo<FareForm> pageInfo = new PageInfo<>(forms);
            return Result.success(pageInfo, "查询成功");
        }
        return Result.error("查询失败");
    }


    @GetMapping("/bar/{pageNum}/{pageSize}")
    public Result customerOrderByBar(@PathVariable int pageNum,@PathVariable int pageSize) {
        List<FareForm> forms = fareService.findByLimit();
        if (forms != null) {
            HashMap<String, Object> map = new HashMap<>();
            ArrayList<String> x = new ArrayList<>();
            ArrayList<Double> y1 = new ArrayList<>();
            ArrayList<Double> y2 = new ArrayList<>();
            ArrayList<Double> y3 = new ArrayList<>();
            ArrayList<Double> y4 = new ArrayList<>();
            ArrayList<Double> y5 = new ArrayList<>();
            ArrayList<Double> y6 = new ArrayList<>();

            for (FareForm form : forms) {
                x.add(form.getName());
                y1.add(form.getRebates());
                y2.add(form.getPrepaidAmount());
                y3.add(form.getPrepaidAmount());
                y4.add(form.getDeliveryFare());
                y5.add(form.getFare());
                y6.add(form.getPremium());
            }
            map.put("x",x);
            map.put("y1",y1);
            map.put("y2",y2);
            map.put("y3",y3);
            map.put("y4",y4);
            map.put("y5",y5);
            map.put("y6",y6);

            return Result.success(map, "查询成功");
        }
        return Result.error("查询失败");
    }

    @GetMapping("/bar/{pageNum}/{pageSize}/{date}")
    public Result customerOrderByBarAndLimit(@PathVariable int pageNum,@PathVariable int pageSize,@PathVariable String date) {
        List<FareForm> forms = fareService.findByLimitDate(date);
        System.out.println(forms);
        if (forms != null) {
            HashMap<String, Object> map = new HashMap<>();
            ArrayList<String> x = new ArrayList<>();
            ArrayList<Double> y1 = new ArrayList<>();
            ArrayList<Double> y2 = new ArrayList<>();
            ArrayList<Double> y3 = new ArrayList<>();
            ArrayList<Double> y4 = new ArrayList<>();
            ArrayList<Double> y5 = new ArrayList<>();
            ArrayList<Double> y6 = new ArrayList<>();

            for (FareForm form : forms) {
                x.add(form.getName());
                y1.add(form.getRebates());
                y2.add(form.getPrepaidAmount());
                y3.add(form.getPrepaidAmount());
                y4.add(form.getDeliveryFare());
                y5.add(form.getFare());
                y6.add(form.getPremium());
            }
            map.put("x",x);
            map.put("y1",y1);
            map.put("y2",y2);
            map.put("y3",y3);
            map.put("y4",y4);
            map.put("y5",y5);
            map.put("y6",y6);
            System.out.println(map);
            return Result.success(map, "查询成功");
        }
        return Result.error("查询失败");
    }

}